package com.gome.axwl.aoc.service.impl;

import com.gome.axwl.aoc.entity.po.OrderSearchPo;
import com.gome.axwl.aoc.entity.po.WaybillSearchPo;
import com.gome.axwl.aoc.service.OrderService;
import com.gome.axwl.aoc.service.feign.MasterDataFeignClient;
import com.gome.axwl.aoc.service.feign.OrderFeignClient;
import com.gome.common.utils.StringUtil;
import com.gome.commons.core.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("orderService")
public class OrderServiceImpl implements OrderService {

    @Autowired
    private MasterDataFeignClient masterDataFeignClient;

    @Autowired
    private OrderFeignClient orderFeignClient;

    /**
     * 模糊查询服务商
     *
     * @param keyword
     * @return
     */
    @Override
    public Object getCarrierByKeyword(String keyword, String dcId) {
        return masterDataFeignClient.QueryCarrierByKeyword(keyword, dcId);
    }

    /**
     * 分页查询订单集合
     *
     * @param orderSearchPo
     * @return
     */
    @Override
    public ResultData getOrderList(OrderSearchPo orderSearchPo) {
        if (StringUtil.isEmpty(orderSearchPo.getCustomerAccount())) {
            orderSearchPo.setCustomerAccount(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getOrderNo())) {
            orderSearchPo.setOrderNo(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getCarrierId())) {
            orderSearchPo.setCarrierId(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getServiceProviderId())) {
            orderSearchPo.setServiceProviderId(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getTaskNo())) {
            orderSearchPo.setTaskNo(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getWaybillNo())) {
            orderSearchPo.setWaybillNo(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getOrderType())) {
            orderSearchPo.setOrderType(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getStatus())) {
            orderSearchPo.setStatus(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getPickEndTime())) {
            orderSearchPo.setPickEndTime(null);
        }
        if (StringUtil.isEmpty(orderSearchPo.getPickStartTime())) {
            orderSearchPo.setPickStartTime(null);
        }
        return orderFeignClient.getOrderList(orderSearchPo.getOrderNo(), orderSearchPo.getCustomerAccount(), orderSearchPo.getServiceProviderId(), orderSearchPo.getCarrierId(), orderSearchPo.getStatus(), orderSearchPo.getPickStartTime(),
                orderSearchPo.getPickEndTime(), orderSearchPo.getDeliverStartTime(), orderSearchPo.getDeliverEndTime(), orderSearchPo.getAcceptDcIds(), orderSearchPo.getPageNum(), orderSearchPo.getPageSize(), orderSearchPo.getTaskNo(), orderSearchPo.getWaybillNo(), orderSearchPo.getOrderType());
    }

    /**
     * 根据订单号查询运单列表
     *
     * @param waybillSearchPo
     * @return
     */
    @Override
    public ResultData getWaybillByOrderNo(WaybillSearchPo waybillSearchPo) {
        return orderFeignClient.getWaybillByOrderNo(waybillSearchPo.getPageSize(), waybillSearchPo.getPageNum(), waybillSearchPo.getTaskNo(), waybillSearchPo.getOrderId());
    }

    /**
     * 查询订单详情
     *
     * @param orderNo
     * @return
     */
    @Override
    public ResultData getOrderDetail(String orderNo) {
        return orderFeignClient.getOrderDetail(orderNo);
    }

    /**
     * 查询运单详情
     *
     * @param waybillNo
     * @return
     */
    @Override
    public ResultData getWaybillDetail(String waybillNo) {
        return orderFeignClient.getWaybillDetail(waybillNo);
    }

    /**
     * 状态字典查询
     *
     * @param code
     * @return
     */
    @Override
    public ResultData getStatus(String code) {
        return orderFeignClient.getStatus(code);
    }


}
